package com.dfe.backend.common.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 【描述】：虚拟地址映射
 *
 * @author LiChang
 * @since 2025-8-4 8:52
 */
@Configuration
public class FileConfig extends WebMvcConfigurerAdapter {
    @Value("${file.windows.path}")
    private String windowsSavePath;

    @Value("${file.windows.virtualPath}")
    String windowsVirtualPath;

    @Value("${file.linux.path}")
    private String linuxSavePath;

    @Value("${file.linux.virtualPath}")
    String linuxVirtualPath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 判断系统
        String os = System.getProperty("os.name");
        if (os.toLowerCase().startsWith("win")) {
            registry.addResourceHandler(windowsVirtualPath).addResourceLocations("file:" + windowsSavePath + "/");
        } else {
            registry.addResourceHandler(linuxVirtualPath).addResourceLocations("file:" + linuxSavePath + "/");
        }
    }
}
